package com.xiaoxie.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.xiaoxie.cloud.apis.PayFeignApi;
import com.xiaoxie.cloud.entities.PayDTO;
import com.xiaoxie.cloud.resp.ResultData;
import com.xiaoxie.cloud.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
public class OrderController {

    private final PayFeignApi payFeignApi;

    @PostMapping("/feign/pay/add")
    public ResultData addOrder(@RequestBody PayDTO payDTO) {
        ResultData resultData = payFeignApi.addPay(payDTO);
        return resultData;
    }

    @GetMapping("/feign/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id) {

        ResultData resultData = null;

        try {
            log.info("调用开始...,{}", DateUtil.now());
            resultData = payFeignApi.getPayInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("调用结束...,{}", DateUtil.now());
            ResultData.fail(ReturnCodeEnum.RC500.getCode(), e.getMessage());
        }
        // resultData = payFeignApi.getPayInfo(id);
        return resultData;
    }

    @GetMapping("/feign/pay/mylb")
    public String mylb() {
        return payFeignApi.mylb();
    }

}
